﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YArchitech.Temp
{
	internal class FlowToSpecifications : SortedSet<FlowToSpecification>
	{
		public HYDuctSpecification GetSpecification(double flow)
		{
			foreach (FlowToSpecification flowToSpecification in this)
			{
				if (FlowToSpecification.FlowEqual(flowToSpecification.Flow, flow))
				{
					return flowToSpecification.Specification;
				}
			}
			return null;
		}

		public HYDuctSpecification GetMaxSpecifictaion(double flow)
		{
			IOrderedEnumerable<FlowToSpecification> orderedEnumerable = from fs in this
			where fs.Flow < flow
			orderby fs.Flow descending
			select fs;
			if (orderedEnumerable == null || orderedEnumerable.Count<FlowToSpecification>() == 0)
			{
				return null;
			}
			return orderedEnumerable.First<FlowToSpecification>().Specification;
		}
	}
}
